#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int x, y;

    while (EOF != scanf("%d %d", &x, &y)) {
        printf("%d\n", x % y);
    }

    return 0;
}
